<?php
namespace app\admin\model;
class Activity
{
 public static function getHallList($currentPage=1,$count=20,$type=0,$searchKey=null,$beginTime=null,$endTime=null)
 {
  $startlimit = 0;
  $beginTimeWehre = null;
  $endTimeWehre = null;
  $activityTypeWhere = null;
  $searchWhere = null;
  if($currentPage<>1){$startlimit = ($currentPage-1)*$count;}
  if($type!=0)
  {
  $activityTypeWhere = " and t.activityType = {$type}";
  }
  if($beginTime)
  {
  $beginTimeWehre = " and t.releaseTime > '{$beginTime}'";
  if($endTime)
  {
   $endTimeWehre = " and t.releaseTime < '{$endTime}'";
  }
  }
  if($searchKey)
  {
   $searchWhere  = " and t.Title like '%{$searchKey}%'";
  }
   $totalCount = \think\Db::query("select count(1) as totalCount from youhuer.ocenter_activity  t where 1=1 and status in (0,1,2) {$activityTypeWhere} {$beginTimeWehre} {$endTimeWehre} {$searchWhere} ")[0]['totalCount'];
  $activityList = \think\Db::query("select * from (select activityId,Title,releaseTime,appBrowseCount,activityType,status from youhuer.ocenter_activity t where 1=1 and status in (0,1,2) {$activityTypeWhere} {$beginTimeWehre} {$endTimeWehre} {$searchWhere} order by createTime desc limit {$startlimit},{$count}) t1 left join (select id,activityName from youhuer.ocenter_usertoactivitytype  ) t2  on t1.activityType = t2.id ");
  $float  = $totalCount/$count;
  if(is_int($float))
  {
  $totalPage = $float;
  }else
  {
  if($float>0)
  {
  $totalPage = ceil($float);
  }
  }
  $currentCount = count($activityList);
  $pageArrary = array();
  $page = $currentPage;
  if($totalPage<=5)  ///如果总页小于或等于5页，直接遍历5次填充
  {
  for($int = 1;$int<=$totalPage;$int++)
  {
  array_push($pageArrary,array('id'=>$int));
  }
  }else  //如果页面大于5页，则执行
  {
  if($currentPage<=3)  //如果当前页小于3的话，直接写3为中间,页面1-5
  {
  for($int = 1;$int<=5;$int++)
  {
  $pageArrary = array(array('id'=>1),array('id'=>2),array('id'=>3),array('id'=>4),array('id'=>5));
  }
  }else   //否则，为当前页面大于第3页，需要填充后面的两个页
  {
   $pageArrary = array(array('id'=>$currentPage-2),array('id'=>$currentPage-1),array('id'=>$currentPage));
   for($s=1;$s<=2;$s++)
   {
   if($page<$totalPage)
   {
   $page++;
   array_push($pageArrary,array('id'=>$page));
   }

   }
  }
  }
  return array('activityList'=>$activityList,'totalCount'=>$totalCount,'currentPage'=>$currentPage,'currentCount'=>$currentCount,'totalPage'=>$totalPage,'pageArray'=>$pageArrary);
 }
 public static function getActivityTyle($type=70)
 {
 return \think\Db::query("SELECT userTypeId,username,activityId,activityName,id FROM youhuer.ocenter_usertoactivitytype WHERE userTypeId = {$type} and status =1 order by activityId");
 }
 public static function getEducationalType()
 {
 return array('0'=>array('name'=>'无要求','id'=>0),'1'=>array('name'=>'专科','id'=>1),'2'=>array('name'=>'本科','id'=>2),'3'=>array('name'=>'研究生','id'=>3),'4'=>array('name'=>'博士','id'=>4));
 }
 public static function getJobsType()
 {
 return array('1'=>array('name'=>'全职','id'=>1),'2'=>array('name'=>'兼职','id'=>2),'3'=>array('name'=>'实习','id'=>3));
 }
 public static function release($Title,$activityType,$content,$imageData,$industryId,$cityId,$educationalType,$salaryType,$experienceType,$jobsType,$sponsorUid=10600,$day=30)
 {
 $noticeId = 'N'.date('YmdHis').rand(1000,9999);
 $activityId = 'A'.date('YmdHis').rand(1000,9999);
 $releaseTime = date("Y-m-d H:i:s");
 $deadline = date("Y-m-d H:i:s",strtotime("+{$day} day"));
 $type = 'feed';
 $array = array();
 $array['attach_ids']=$imageData;
 if($imageData){ $type = 'image';};
 $array = serialize($array);
 $noticeData = array('activityId'=>$activityId,'noticeId'=>$noticeId,'content'=>$content,'title'=>$Title,'createTime'=>$releaseTime,'releaseTime'=>$releaseTime,'status'=>1,'type'=>$type,'data'=>$array);
$result = \think\Db::table('youhuer.ocenter_notice')->insert($noticeData);
if($result)
{
$activityData = array('activityId'=>$activityId,'sponsorUid'=>$sponsorUid,'Title'=>$Title,'activityType'=>$activityType,'status'=>1,'releaseTime'=>$releaseTime,'deadline'=>$deadline,'industryId'=>$industryId,'cityId'=>$cityId,'educationalType'=>$educationalType,'salaryType'=>$salaryType,'experienceType'=>$experienceType,'jobsType'=>$jobsType,'businessId'=>$noticeId);
 $result = \think\Db::table('youhuer.ocenter_activity')->insert($activityData);
 return $activityId;
}


 }
 public static function delete($activityId)
 {
 \think\Db::query("update youhuer.ocenter_activity set status = 4 where activityId = '{$activityId}'");
 \think\Db::query("update youhuer.ocenter_notice set status = 4 where activityId = '{$activityId}'");
 }
 public static function getScaleMode()
 {
  return array('0'=>array('value'=>'未填写','id'=>0),'1'=>array('value'=>'50人以下','id'=>1),'2'=>array('value'=>'50-100人','id'=>2),'3'=>array('value'=>'100-500人','id'=>3),'4'=>array('value'=>'500-1000人','id'=>4),'5'=>array('value'=>'1000-5000人','id'=>5),'6'=>array('value'=>'5000-10000人','id'=>6),'7'=>array('value'=>'10000人以上','id'=>7));
  //规模
 }
 public static function getIndustryInfo($industryId)
 {
 $result = \think\Db::query();
 }





}